﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Windows.Forms;
using System.IO;
using System.Configuration;

namespace FileOperationWinform
{
    public class FileResourceAuto
    {
        public delegate void lisete(object obj, string msg);
        public event lisete Altem;

        private string x;
        public string testmes
        {
            get
            {
                return x;
            }set{
                x = value;
            if (Altem!=null)
            {
                Altem(this, "sadga");
            }
            }
        }
        public void FileAuto(string str,int  ResoureName)
        {
            string path = Application.StartupPath + @"\";
            if (!File.Exists(path + str))
            {
                FileStream fs = new FileStream(path + str, FileMode.CreateNew, FileAccess.Write);
                byte[] buffer;
                switch (ResoureName)
                {
                    case 0:
                        buffer = FileOperationWinform.Properties.Resources.FileOpeationHelp;
                        fs.Write(buffer, 0, buffer.Length);
                        break;
                    case 1:
                        buffer = FileOperationWinform.Properties.Resources.IrisSkin2;
                        fs.Write(buffer, 0, buffer.Length);
                        break;
                    case 2:
                        buffer = FileOperationWinform.Properties.Resources.ZedGraph;
                        fs.Write(buffer, 0, buffer.Length);
                        break;
                    case 3:
                        buffer = FileOperationWinform.Properties.Resources.MSN1;
                        fs.Write(buffer, 0, buffer.Length);
                        break;
                    case 4:
                        buffer = FileOperationWinform.Properties.Resources.vista11;
                        fs.Write(buffer, 0, buffer.Length);
                        break;
                    case 5:
                        buffer = FileOperationWinform.Properties.Resources.SportsBlack1;
                        fs.Write(buffer, 0, buffer.Length);
                        break;
                    case 6:
                        buffer= FileOperationWinform.Properties.Resources.Eighteen;
                        fs.Write(buffer, 0, buffer.Length);
                        break;
                    case 7:
                        buffer = FileOperationWinform.Properties.Resources.Emerald;
                        fs.Write(buffer, 0, buffer.Length);
                        break;
                }
                fs.Close();
            }
        }
        public void FileConfigureAuto()
        {
            string path = Application.StartupPath + @"\";
            if (!File.Exists(path + "FileOperationSystem.config"))
            {
                string key = "SKin";
                string value = @"Skin\MSN.ssk";
                string key_help = "Help";
                string key_helpvalue = "FileOpeationHelp.chm";
                string key_Except = "Except";
                string key_ExceptValue = "FileExcept.Config";
                string key_Skinfile = "SkinFile";
                string key_SkinFileValue = "FileSkin.Config";
                string sectionName = "appSettings";
                Configuration configure = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                configure.AppSettings.Settings.Add(key, value);
                configure.AppSettings.Settings.Add(key_help, key_helpvalue);
                configure.AppSettings.Settings.Add(key_Except, key_ExceptValue);
                configure.AppSettings.Settings.Add(key_Skinfile, key_SkinFileValue);

                configure.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection(sectionName);

            }
        }
    }
}
